#include <iostream>
#include <memory>
#include <gflags/gflags.h>
#include "../../common/data_es.hpp"
#include "../../common/data_es.hpp"

DEFINE_bool(run_mode, false, "程序的运行模式，false-调试； true-发布；");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 1, "发布模式下，用于指定日志输出等级");

DEFINE_string(es_host_list,"http://127.0.0.1:9200/","es服务器的URL");

int main(int argc, char *argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    zrb::init_logger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    auto client = zrb::ESClientFactory::create(FLAGS_es_host_list);
    auto user = std::make_shared<zrb::ESUser>(client);

    user->createIndex();
    user->appendData("uid1","昵称1","13536271727","","111");
    user->appendData("uid2","昵称2","13536331727","","222");
    user->appendData("uid3","昵称3","13536123727","","333");
    user->appendData("uid4","昵称4","13536232177","","444");
    user->appendData("uid5","昵称5","13531111127","","555");

    auto res = user->search("昵称",{"uid4"});
    for(auto& e : res)
    {
        std::cout << e.user_id() << std::endl;
        std::cout << e.nickname() << std::endl;
        std::cout << e.phone() << std::endl;
        std::cout << e.avatar_id() << std::endl;
    }

    return 0;
}